package com.zxy.furns.utils;

import com.zxy.furns.entity.Furn;

import java.math.BigDecimal;

/**
 * ClassName: FurnData
 * Package: com.hspedu.furns.utils
 *
 * @Author zxy
 * @Create 2025/3/4 18:13
 * @Version 1.0
 * title:
 * Description:
 */
public class FurnDataCheckUtils {
    public static boolean validateFurn(Furn furn) {
        if (furn == null) {
            return false;
        }

        //检查家具名name
        if (furn.getName() == null || furn.getName().trim().isEmpty()) {
            System.out.println("家具名称不能为空！");
            return false;
        }

        //检查商家名maker
        if (furn.getMaker() == null || furn.getMaker().trim().isEmpty()) {
            System.out.println("商家名不能为空！");
            return false;
        }

        //检查价格的合法性
        if (furn.getPrice() == null || furn.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
            System.out.println("价格输入不合法！");
            return false;
        }

        // 检查 sales 是否为有效整数且大于等于 0
        if (furn.getSales() == null || furn.getSales() < 0) {
            System.out.println("Furn sales must be a non-negative integer.");
            return false;
        }

        // 检查 stock 是否为有效整数且大于等于 0
        if (furn.getStock() == null || furn.getStock() < 0) {
            System.out.println("Furn stock must be a non-negative integer.");
            return false;
        }
        return true;
    }
//        if (furn == null) {
//            return false;
//        }
//
//        // 检查 name 是否为空
//        if (furn.getName() == null || furn.getName().trim().isEmpty()) {
//            System.out.println("Furn name cannot be empty.");
//            return false;
//        }
//
//        // 检查 maker 是否为空
//        if (furn.getMaker() == null || furn.getMaker().trim().isEmpty()) {
//            System.out.println("Furn maker cannot be empty.");
//            return false;
//        }
//
//        // 检查 price 是否为有效数字且大于 0
//        if (furn.getPrice() == null || furn.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
//            System.out.println("Furn price must be a valid positive number.");
//            return false;
//        }
//
//        // 检查 sales 是否为有效整数且大于等于 0
//        if (furn.getSales() == null || furn.getSales() < 0) {
//            System.out.println("Furn sales must be a non-negative integer.");
//            return false;
//        }
//
//        // 检查 stock 是否为有效整数且大于等于 0
//        if (furn.getStock() == null || furn.getStock() < 0) {
//            System.out.println("Furn stock must be a non-negative integer.");
//            return false;
//        }
//
//        return true;
//    }
}

